home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / TCL1 / __MANDEL / MANDELBR / CMANDELP.C2 < prev    next >
Text File  |  1992-05-31  |  2KB  |  106 lines

  1. /****
  2.  * CMandelPane.c
  3.  *
  4.  *  Copyright ⌐ 1990 Symantec Corporation.  All rights reserved.
  5.  *
  6.  ****/
  7.  
  8. #include "CMandelDoc.h"
  9. #include "CMandelPane.h"
  10. #include "CMandelMap.h"
  11. #include "LongQD.h"
  12. #include <Global.h>
  13.  
  14. #define itsMandelMap    ((CMandelMap *)itsPixMap)
  15. #define itsMandelDoc    ((CMandelDoc *)itsSupervisor)
  16.  
  17. void CMandelPane::IMandelPane(CView *anEnclosure, CBureaucrat *aSupervisor,
  18.                             short aWidth, short aHeight,
  19.                             short aHEncl, short aVEncl,
  20.                             SizingOption aHSizing, SizingOption aVSizing,
  21.                             CMandelMap *aMandelMap)
  22. {
  23.     long        i;
  24.     
  25.     CPixMapPane::IPixMapPane(anEnclosure, aSupervisor, aWidth, aHeight,
  26.                             aHEncl, aVEncl, aHSizing, aVSizing, (CPixMap *)aMandelMap);
  27.     
  28.     SetWantsClicks(TRUE);
  29. }
  30.  
  31. void CMandelPane::DoClick(Point hitPt, short modifierKeys, long when)
  32. {
  33.     double    aHOrigin, aVOrigin;
  34.     double    aPtRatio, aRectRatio;
  35.     short    aWidth, aHeight;
  36.     Rect    aRect, aTempRect;
  37.     Point    aPoint, aLastPt, aOrigin;
  38.     KeyMap    aKeyMap;
  39.     
  40.     aOrigin.h = hitPt.h;
  41.     aOrigin.v = hitPt.v;
  42.     itsMandelDoc->QDToReal(aOrigin, &aHOrigin, &aVOrigin);
  43.     
  44.     if ((modifierKeys & cmdKey) != cmdKey)
  45.     {
  46.         aWidth = itsMandelDoc->GetWidth();
  47.         aHeight = itsMandelDoc->GetHeight();
  48.         aRectRatio = (double)aWidth / (double)aHeight;
  49.         
  50.         aLastPt = hitPt;
  51.         topLeft(aRect) = hitPt;
  52.         botRight(aRect) = hitPt;
  53.         
  54.         PenMode(patXor);
  55.         FrameRect(&aRect);
  56.         
  57.         while (StillDown())
  58.         {
  59.             GetMouse(&aPoint);
  60.             if (EqualPt(aLastPt, aPoint))
  61.                 continue;
  62.             
  63.             aWidth = aPoint.h - hitPt.h;
  64.             aHeight = aPoint.v - hitPt.v;
  65.             aWidth = Abs(aWidth);
  66.             aHeight = Abs(aHeight);
  67.             
  68.             aPtRatio = (double)aWidth / (double)aHeight;
  69.             if (aPtRatio > aRectRatio)
  70.                 aHeight = (double)aWidth / aRectRatio;
  71.             else
  72.                 aWidth = (double)aHeight * aRectRatio;
  73.     
  74.             aTempRect.top = hitPt.v - aHeight;
  75.             aTempRect.left = hitPt.h - aWidth;
  76.             aTempRect.bottom = hitPt.v + aHeight;
  77.             aTempRect.right = hitPt.h + aWidth;
  78.     
  79.             FrameRect(&aTempRect);
  80.             FrameRect(&aRect);
  81.             
  82.             aRect = aTempRect;
  83.             aLastPt = aPoint;
  84.         }
  85.         
  86.         FrameRect(&aRect);
  87.         PenNormal();
  88.         
  89.         GetKeys(&aKeyMap);
  90.         if (BitTst(&aKeyMap, 61))    /* option key */
  91.             return;
  92.  
  93.         itsMandelDoc->SetScale(itsMandelDoc->GetScale() *
  94.             (((double)aWidth * 2.) / (double)itsMandelDoc->GetWidth()));
  95.     }
  96.     
  97.     itsMandelDoc->SetOrigin(aHOrigin, aVOrigin);
  98.     itsMandelDoc->DoGenerate();
  99. }
  100.  
  101. void CMandelPane::AdjustCursor(Point where, RgnHandle mouseRgn)
  102.  
  103. {
  104.     SetCursor(*GetCursor(crossCursor));
  105. }
  106.